package web;

import domain.User;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/queryListServlet")
public class QueryListServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1:接收请求,没有参数传到业务层(需求查询所有的用户)
        //2:处理业务逻辑
        //面向接口编程
        //父接口                   父接口的实现子类(多态)
        UserService user = new UserServiceImpl();
        List<User> list =user.findList();

        //测试是否获取成功
        System.out.println("list = " + list);

        //3:响应数据
        request.getSession().setAttribute("list",list);
        response.sendRedirect("/list.jsp");

    }

}
